#============================================
# #知识点
#先进先出
from multiprocessing import Queue
dl = Queue(5)
for i in range(5):
    dl.put(i)
    print(dl.empty())#判断队列是否为空
print("判断是否为满>>",end = "")
print(dl.full())  #判断是否为满
for i in range(5):
    print(dl.get(i))    
print("判断是否为空>>",end = "")
#下面三种方法不能用在异步处理
print(dl.empty())
dl.get_nowait() #没有数据获取报错为 _queue.Empty
dl.get(timeout=3) #没有数据获取,3秒后报错为 _queue.Empty
#============================================
# IPC机制通过队列可以实现
#子进程和主进程之间得通信，已经子进程和子进程之间得通信
from multiprocessing import Process,Queue
def fasong(dl):
    dl.put("你好")

def jieshou(dl):
    print(dl.get())

if __name__ == "__main__":
    dl = Queue(10)
    obj1 = Process(target=fasong,args=(dl,))
    obj2 = Process(target=jieshou,args=(dl,))
    obj2.start()
    obj1.start()
    obj2.join()
    print("完成!")
#============================================